<?php
defined('BASEPATH') OR exit('No direct script access allowed');
/**
 * 系统设置
 */
class Setup extends JS_Controller {

	public function __construct() {
		parent::__construct();
		if($this->session->suser->group != 1){
			show_error('参数错误！');
		}
	}

	public function index(){
		//获取系统信息
		$res = $this->system_mdl->get_one();
		$data['sys'] = $res;
		$this->_view('setup_index',$data);
	}

	/**
	 * 修改系统信息
	 */
	public function update(){
		$post = $this->input->post(NULL,TRUE);

		if(!$this->input->is_ajax_request()){
			show_404();
		}

		if(empty($post['url'])){
			die('网站域名不能为空');
		}
		if(empty($post['title'])){
			die('网站名称不能为空');
		}

		if(empty($post['status'])){
			die('参数错误！');
		}

		if(!preg_match("/^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$/",$post['email'])){
			die('邮箱格式错误！');
		}

		$this->db->where('id',1);
		$res = $this->system_mdl->update($post);
		echo $res === true ? '1' : '修改系统信息失败！';
	}

}

/* End of file Setup.php */
/* Location: ./application/controllers/Setup.php */